package com.endbd.systemmanagement.service.logs;

import com.endbd.feignapi.model.system.Journal;
import com.endbd.systemmanagement.dao.logs.LogDao;
import com.endbd.systemmanagement.model.LogCondition;
import com.endbd.systemmanagement.model.PageUsers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class LogServiceImpl implements LogService{

  @Autowired
  private LogDao logDao;

  @Override
  public PageUsers<Journal> getLogList(Integer page, Integer size, LogCondition logCondition) {
    PageHelper.startPage(page,size);
    List<Journal> list=logDao.getLogList(logCondition);
    PageInfo<Journal> info=new PageInfo<>(list);
    PageUsers<Journal> ans=new PageUsers<>();
    ans.setPage(page);
    ans.setSize(size);
    ans.setTotalSize((int) info.getTotal());
    ans.setList(list);
    return ans;
  }

  @Override
  public boolean recordLog(Journal journal) {
    return logDao.recordLog(journal)==1;
  }
}
